|
|
|
| Table 20.3 Methods of the TextStream Class. | | Method | Description | | CloseFile | Closes the file when youre through with it. This method is also called from the Class_Terminate() event. | | OpenTextFile | Opens a file for reading or appending. Youll pass in the filename and the mode for opening the file. | | ReadLine | Reads a line of data from the text file up to but not including the carriage return and linefeed characters. | | WriteLine | Writes a line of data to the text file with a carrigage return and line feed placed onto the end of the line. |
|
|
|
|
|
|
Lets look at the how you would use the TextStream class in an application. Ive left out a lot of the error handling just to keep the examples short and understandable; however, in a production application, you would want to have the appropriate error handling in all of these routines. |
|
|
|
|
|
|
|
|
Writing to a File Using the TextStream Class |
|
|
|
|
|
|
|
|
Youll start out by learning how to write information from a text box into a text file. The form shown in Figure 20.3 has a text box in which you can type some text. It also has a text box that accepts a filename to write information into. After youve entered this text, the Write button can be clicked to put the information into the appropriate text file. |
|
|
|
|
|
|
|
|
Examples Filename: FileWrite.frm |
|
|
|
|
|
|
|
|
Figure 20.3
Writing to a text file using the TextStream class. |
|
|
|
|
|